<template>
	<view class="content">
		<view class="drop" v-show="clickShow">
			<view class="shape"></view>
			<view class="dropItem">
				<image src="../../static/tabimg/mima.png" class="imgCode"></image>
				<view @tap="changepass">修改密码</view>
			</view>
			<view class="dropItem">
				<image src="../../static/tabimg/tuichu.png" class="imgCode2"></image>
				<view @tap="close">退出应用</view>
			</view>
		</view>
		<!-- 内容主体 -->
		<view>
			<view class="uni-swiper-tab">
				<view v-for="(item,index) in tabBars" :key="index" class="swiper-tab-list" :class="tabIndex==index ? 'active' : ''"
				 @click="tapTab" :data-current="index">{{item.name}}</view>
			</view>
		</view>
		<view v-show="tab0" class="hezi">
			<view class="Roughing">
				<view class="Roughingbox hide">
					<view class="timetab">
						<view class="timelist">
							<view class="day" v-for="(item,index) in timelist2" :key="index" :class="index ==timeIndex2? 'month':''" @tap="changetime(index)">{{item.name}}</view>
						</view>
					</view>
					<view class="infomain">
						<view class="yieldcount">
							<view class="name">轧制块数:<text class="blue">{{title1}}</text></view>
							 <uChart :show="canvas" :canvasId="zhazhi.id" :chartType="zhazhi.chartType" :extraType="zhazhi.extraType"
							  :cWidth="cWidth" :cHeight="cHeight" :opts="zhazhi.opts" :ref="zhazhi.id" />
							<view class="name">轧制长度:<text class="blue">{{title2}}</text></view>
							 <uChart :show="canvas" :canvasId="zhazhiLen.id" :chartType="zhazhiLen.chartType" :extraType="zhazhiLen.extraType"
							  :cWidth="cWidth" :cHeight="cHeight" :opts="zhazhiLen.opts" :ref="zhazhiLen.id" />
							<view class="name">轧制重量:<text class="blue">{{title3}}</text></view>
							 <uChart :show="canvas" :canvasId="zhazhiWid.id" :chartType="zhazhiWid.chartType" :extraType="zhazhiWid.extraType"
							  :cWidth="cWidth" :cHeight="cHeight" :opts="zhazhiWid.opts" :ref="zhazhiWid.id" />
						</view>
					</view>
				</view>
			</view>
		</view>
		<view v-show="tab1" class="hezi">
			<view class="Roughing">
				<view class="Roughingbox hide">
					<view class="control">
						<view class="controllist">
							<view class="controllist-item">当前班</view>
							<view class="controllist-item">当前组</view>
							<view class="controllist-item">块数</view>
							<view class="controllist-item">产量</view>
							<view class="controllist-item">状态</view>
						</view>
						<view class="controllist controllist-val">
							<view class="controllist-item">{{nowclass}}</view>
							<view class="controllist-item">{{group}}</view>
							<view class="controllist-item">{{blocks}}</view>
							<view class="controllist-item">{{output}}</view>
							<view class="controllist-item">{{status}}</view>
						</view>
						<view class="yieldcount">
							<view class="name">当前班精度(%)</view>
							<uChart :show="canvas" :canvasId="banjing.id" :chartType="banjing.chartType" :extraType="banjing.extraType"
							 :cWidth="cWidth" :cHeight="cHeight" :opts="banjing.opts" :ref="banjing.id" />
						</view>
					</view>
				</view>
			</view>
		</view>
		<view v-show="tab2" class="hezi">
			<view class="Roughing">
				<view class="Roughingbox hide">
					<view class="timetab">
						<view class="timelist">
							<view class="day" v-for="(item,index) in timelist1" :key="index" :class="index ==timeIndex1? 'month':''" @tap="changetime2(index)">{{item.name}}</view>
						</view>
					</view>
					<view class="infomain scroll-Y">
						<view class="yieldcount mT20">
							<u-charts :canvas-id="mingzhong.id" :chartType="mingzhong.chartType" :cWidth="cWidth" :cHeight="cHeight" :opts="mingzhong.opts"
							 :ref="mingzhong.id" />
						</view>
					</view>
				</view>
			</view>
		</view>
		<view v-show="tab3" class="hezi">
			<view class="Roughing">
				<view class="Roughingbox hide">
					<view class="timetab">
						<view class="timelist">
							<view class="day" v-for="(item,index) in timelist" :key="index" :class="index ==timeIndex? 'month':''" @tap="changetime1(index)">{{item.name}}</view>
						</view>
					</view>
					<view class="infomain">
						<view class="yieldcount">
							<uChart :show="canvas" :canvasId="tingji.id" :chartType="tingji.chartType" :extraType="tingji.extraType"
							 :cWidth="cWidth" :cHeight="cHeight" :opts="tingji.opts" :ref="tingji.id" />
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		post
	} from '@/lib/Util.js'
	import uCharts from '@/components/u-charts/component.vue';
	import uChart from '@/components/leiqch-ucharts/u-charts.vue';
	import {
		mapState,
		mapMutations
	} from 'vuex';
	var _self;

	export default {
		data() {
			return {
				clickShow: false,
				flag: true,
				arry: [],
				arry2: [],
				arry3: [],
				//标题
				title1: '---',
				title2: '---',
				title3: '---',
				textarea: '',
				cWidth: '',
				cHeight: '',
				arr: [],
				canvas: true,
				//雷达图
				banjing: {
					opts: {},
					chartType: "radar",
					extraType: "",
					id: "banjing"
				},
				//命中率统计
				mingzhong: {
					opts: {},
					chartType: "column",
					extraType: "",
					id: "mingzhong"
				},
				//选项卡切换
				tabBars: [{
					name: '产量统计',
					id: 'chanliangtongji'
				}, {
					name: '控制精度',
					id: 'kongzhi'
				}, {
					name: '命中率统计',
					id: 'mingzhong'
				}, {
					name: '停机统计',
					id: 'tingji',
				}],
				scrollLeft: 0,
				tabIndex: 0,
				tab0: true,
				tab1: false,
				tab2: false,
				tab3: false,

				//班精度
				nowclass: '',
				group: '',
				blocks: '', //块数
				output: '', //产量
				status: '', //状态

				//时间切换
				timeIndex: 0,
				timelist: [{
						name: '日',
						id: 0
					},
					{
						name: '周',
						id: 1
					},
					{
						name: '年',
						id: 3
					}
				],
				//命中率时间切换
				timeIndex1: 0,
				timelist1: [{
						name: '日',
						id: 0
					},
					{
						name: '周',
						id: 1
					},
					{
						name: '年',
						id: 3
					}
				],
				//产量统计时间切换
				timeIndex2: 0,
				timelist2: [{
						name: '日',
						id: 0
					},
					{
						name: '周',
						id: 1
					},
					{
						name: '年',
						id: 3
					}
				],
				//轧制块数
				zhazhi: {
					opts: {},
					chartType: "column",
					extraType: "",
					id: "c1"
				},
				zhazhiLen: {
					opts: {},
					chartType: "column",
					extraType: "",
					id: "abc"
				},
				zhazhiWid: {
					opts: {},
					chartType: "column",
					extraType: "",
					id: "c3"
				},
				//停机统计
				tingji: {
					opts: {},
					chartType: "pie",
					extraType: "",
					id: "tingji"
				},
			}
		},
		components: {
			uCharts,
			uChart
		},
		computed: mapState(['forcedLogin', 'hasLogin', 'userName']),
		onLoad() {
			_self = this;
			this.cWidth = uni.upx2px(730);
			this.cHeight = uni.upx2px(500);
			this.getServerData();   //产量统计
			this.getBanjing();     //班精度
			this.getMingzhong();   //命中率统计
			this.getban();        //班精度
			this.tingjiCount();   // 停机统计
			if (!uni.getStorageSync('hasLogin')) {
				uni.showModal({
					title: '未登录',
					content: '您未登录，需要登录后才能继续',
					showCancel: !this.forcedLogin,
					success: (res) => {
						if (res.confirm) {
							if (this.forcedLogin) {
								uni.reLaunch({
									url: '../login/login'
								});
							} else {
								uni.navigateTo({
									url: '../login/login'
								});
							}
						}
					}
				});
			}
		},
		methods: {
			//选项卡切换
			tapTab(e) {
				let tabIndex = e.target.dataset.current;
				if (this.tabIndex === tabIndex) { //判断重复点击
					return false;
				} else {
					this.tabIndex = tabIndex;
					if (this.tabIndex == 0) {
						this.tab0 = true;
						this.tab1 = false;
						this.tab2 = false;
						this.tab3 = false;
					} else if (this.tabIndex == 1) {
						this.tab1 = true;
						this.tab0 = false;
						this.tab2 = false;
						this.tab3 = false;
					} else if (this.tabIndex == 2) {
						this.tab2 = true;
						this.tab1 = false;
						this.tab0 = false;
						this.tab3 = false;
					} else if (this.tabIndex == 3) {
						this.tab3 = true;
						this.tab1 = false;
						this.tab2 = false;
						this.tab0 = false;
					}
					this.isClickChange = true;
				}
			},

			//产量统计
			async getServerData(val, val1, val2, val3) {
				if (val == 0 || val1 == 0 || val2 == 0) {
					console.log(val)
					let LineA = {
						categories:  ["1","2", "3","4", "5","6", "7","8", "9","10" ,"11","12"],
						series: [{
							name: "轧制块数:",
							data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
						}]
					};
					let LineB = {
						categories:  ["1","2", "3","4", "5","6", "7","8", "9","10" ,"11","12"],
						series: [{
							name: "轧制长度:",
							data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
						}]
					};
					let LineC = {
						categories:  ["1","2", "3","4", "5","6", "7","8", "9","10" ,"11","12"],
						series: [{
							name: "轧制重量:",
							data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
						}]
					};
					this.title1 = '---';
					this.$refs.c1.changeData('c1', LineA);
					this.title2 = '---';
					this.$refs.abc.changeData('abc', LineB);
					this.title3 = '---';
					this.$refs.c3.changeData('c3', LineC)
					return
				}
				this.arry = []
				this.arry2 = [];
				this.arry3 = [];

				let data = val ? val : [{
					sql: "select * from STATISTIC WHERE to_char(DATE_,'YYYY-MM-DD') = '2018-11-28'order by NO"
				}, {
					sql: "select SUM(BLOCKS) as TOTAL from STATISTIC WHERE  to_char(DATE_,'YYYY-MM-DD') = '2018-11-28'"
				}]
				let data1 = val1 ? val1 : [{
					sql: "select * from STATISTIC WHERE to_char(DATE_,'YYYY-MM-DD') = '2018-11-28' order by NO"
				}, {
					sql: "select SUM(LENGTH) as TOTAL from STATISTIC WHERE  to_char(DATE_,'YYYY-MM-DD') = '2018-11-28'"
				}]
				let data2 = val2 ? val2 : [{
					sql: "select * from STATISTIC WHERE to_char(DATE_,'YYYY-MM-DD') = '2018-11-28' order by NO"
				}, {
					sql: "select SUM(WEIGHT) as TOTAL from STATISTIC WHERE to_char(START_TIME,'YYYY-MM-DD') = '2018-11-23'"
				}]
				_self = this;
				let LineA = {
					categories: ["1","2", "3","4", "5","6", "7","8", "9","10" ,"11","12", "13","14" ,"15","16", "17","18", "19","20", "21","22", "23","24"],
					series: [{
						name: "轧制块数:",
						data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
					}]
				};
				let LineB = {
					categories:  ["1","2", "3","4", "5","6", "7","8", "9","10" ,"11","12", "13","14" ,"15","16", "17","18", "19","20", "21","22", "23","24"],
					series: [{
						name: "轧制长度:",
						data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
					}]
				};
				let LineC = {
					categories:  ["1","2", "3","4", "5","6", "7","8", "9","10" ,"11","12", "13","14" ,"15","16", "17","18", "19","20", "21","22", "23","24"],
					series: [{
						name: "轧制重量:",
						data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
					}]
				};
				this.zhazhi.opts = LineA;
				this.zhazhiLen.opts = LineB;
				this.zhazhiWid.opts = LineC;

				uni.request({
					url: 'http://nercar.tpddns.cn:2074/database/executeQuery',
					data: data[0],
					method: 'POST',
					success: function(res) {
						let result = res.data.data;
						let length = result.length > 12 ? 12 : result.length
						for (let i = 0; i < result.length; i++) {
							if (result[i].BLOCK) {
								_self.arry.push(result[i].BLOCK);
							} else {
								_self.arry.push(result[i].BLOCKS);
							}
						}
					}
				});
				post('database/executeQuery', data1[0]).then(res2 => {
					let length = res2.data.length > 12 ? 12 : res2.data.length
					for (let i = 0; i < res2.data.length; i++) {
						this.arry2.push(res2.data[i].LENGTH);
					}
				})
				post('database/executeQuery', data2[0]).then(res3 => {
					let length = res3.data.length > 12 ? 12 : res3.data.length
					for (let i = 0; i < res3.data.length; i++) {
						this.arry3.push(res3.data[i].WEIGHT);
					}
				})

				let str = await post('database/executeQuery', data[1]);
				if (str.data[0].TOTAL !== null) {
					this.title1 = str.data[0].TOTAL;
				}
				let str1 = await post('database/executeQuery', data1[1])
				if (str1.data[0].TOTAL !== null) {
					this.title2 = str1.data[0].TOTAL;
				}
				let str2 = await post('database/executeQuery', data2[1])
				if (str2.data[0].TOTAL !== null) {
					this.title3 = str2.data[0].TOTAL;
				}
				let LineA1 = {
					categories: ["1","2", "3","4", "5","6", "7","8", "9","10" ,"11","12", "13","14" ,"15","16", "17","18", "19","20", "21","22", "23","24"],
					series: [{
						name: "轧制块数:",
						data: this.arry
					}]
				};
				this.$refs.c1.changeData('c1', LineA1)
				let LineB1 = {
					categories:  ["1","2", "3","4", "5","6", "7","8", "9","10" ,"11","12", "13","14" ,"15","16", "17","18", "19","20", "21","22", "23","24"],
					series: [{
						name: "轧制长度:",
						data: this.arry2
					}]
				};
				this.$refs.abc.changeData('abc', LineB1)
				let LineC1 = {
					categories:  ["1","2", "3","4", "5","6", "7","8", "9","10" ,"11","12", "13","14" ,"15","16", "17","18", "19","20", "21","22", "23","24"],
					series: [{
						name: "轧制重量:",
						data: this.arry3
					}]
				};
				this.$refs.c3.changeData('c3', LineC1)
				if(val3 === "week") {
					let LineA1 = {
						categories: ["1","2", "3","4", "5","6", "7"],
						series: [{
							name: "轧制块数:",
							data: this.arry
						}]
					};
					this.$refs.c1.changeData('c1', LineA1)
					let LineB1 = {
						categories:  ["1","2", "3","4", "5","6", "7"],
						series: [{
							name: "轧制长度:",
							data: this.arry2
						}]
					};
					this.$refs.abc.changeData('abc', LineB1)
					let LineC1 = {
						categories:  ["1","2", "3","4", "5","6", "7"],
						series: [{
							name: "轧制重量:",
							data: this.arry3
						}]
					};
					this.$refs.c3.changeData('c3', LineC1)
				}

				
			},

			//控制精度统计
			getBanjing() {
				let Radar = {
					categories: [],
					series: []
				};
				Radar.categories = ['厚度', '宽度', '终温', '卷温', '凸度', '平度', '楔形'];
				Radar.series = [{
					"name": "当前班精度",
					"data": [0, 0, 0, 0, 0, 0]
				}];
				this.banjing.opts = Radar;
			},
			async getban() {
				let data = {
					"tags": [{
						"name": "output",
						"ts": "0"
					}, {
						"name": "CurGroup",
						"ts": "0"
					}, {
						"name": "CurShift",
						"ts": "0"
					}, {
						"name": "AvergRat.CrownRat",
						"ts": "0"
					}, {
						"name": "AvergRat.FlatRat",
						"ts": "0"
					}, {
						"name": "AvergRat.CTRat",
						"ts": "0"
					}, {
						"name": "AvergRat.FDTRat",
						"ts": "0"
					}, {
						"name": "AvergRat.WidRat",
						"ts": "0"
					}, {
						"name": "AvergRat.ThkRat",
						"ts": "0"
					}],
					"msgs": []
				}
				let res = await post("webservice/getHmiData", data);
				let result = res.data.tagList;
				if (result[2].value * 1 === 0) {
					this.nowclass = "白班"
				}
				if (result[2].value * 1 === 1) {
					this.nowclass = "午班"
				}
				if (result[2].value * 1 === 2) {
					this.nowclass = "夜班"
				}
				if (result[1].value === "0") {
					this.group = "甲组"
				}
				if (result[1].value === "1") {
					this.group = "乙组"
				}
				if (result[1].value === "2") {
					this.group = "丙组"
				}
				if (result[1].value === "3") {
					this.group = "丁组"
				}
				this.output = this.toDecimal(result[0].value)

			},
			toDecimal(x) {
				var f = parseFloat(x);
				if (isNaN(f)) {
					return;
				}
				f = Math.round(x * 100) / 100;
				return f;
			},

			//命中率统计
			async getMingzhong(val) {
				var a1, a2, a3, a4, a5, a6, a7, b1, b2, b3, b4, b5, b6, b7, c1, c2, c3, c4, c5, c6, c7;
				let Column = {
					categories: ['厚度', '宽度', '终温', '卷温', '凸度', '平度', '楔形'],
					series: [{
							name: "甲班",
							data: [0, 0, 0, 0, 0, 0, 0]
						}, {
							name: "乙班",
							color: "#f5bb1c",
							data: [0, 0, 0, 0, 0, 0, 0]
						},
						{
							name: "丙班",
							data: [0, 0, 0, 0, 0, 0, 0]
						},
						{
							name: "丁班",
							data: [0, 0, 0, 0, 0, 0, 0]
						}
					]
				};
				this.mingzhong.opts = Column;
				let data = arguments[0] ? arguments[0] : {
					db: "oracle",
					sql: "SELECT CREW,\n" +
						" ROUND(AVG(THKHIT)) AS AVG_THKHIT,\n" +
						" ROUND(AVG(FDTHIT)) AS AVG_FDTHIT,\n" +
						" ROUND(AVG(CRHIT)) AS AVG_CRHIT,\n" +
						" ROUND(AVG(WEHIT)) AS AVG_WEHIT,\n" +
						" ROUND(AVG(WIDHIT)) AS AVG_WIDHIT,\n" +
						" ROUND(AVG(CTHIT)) AS AVG_CTHIT,\n" +
						" ROUND(AVG(FLAHIT)) AS AVG_FLAHIT\n" +
						" FROM V_CREW_STAT\n" +
						" WHERE TIME_DISCHARGE >=\n" +
						" TO_DATE('2018-02-01 0:00:00', 'YYYY-MM-DD HH24:MI:SS')\n" +
						" AND TIME_DISCHARGE <\n" +
						" TO_DATE('2018-02-01 10:00:00', 'YYYY-MM-DD HH24:MI:SS')\n" +
						" GROUP BY CREW\n" +
						" ORDER BY DECODE(CREW, '甲班', 0, '乙班', 1, '丙班', 2, 3) ASC"
				}
				let res = await post('database/executeQuery', data)
				if (res.data.length === 0) {
					this.$refs.mingzhong.changeData('mingzhong', Column)
					return;
				}
				a1 = res.data[0].AVG_THKHIT;
				a2 = res.data[0].AVG_FDTHIT;
				a3 = res.data[0].AVG_CRHIT;
				a4 = res.data[0].AVG_WEHIT;
				a5 = res.data[0].AVG_WIDHIT;
				a6 = res.data[0].AVG_CTHIT;
				a7 = res.data[0].AVG_FLAHIT;

				b1 = res.data[1].AVG_THKHIT;
				b2 = res.data[1].AVG_FDTHIT;
				b3 = res.data[1].AVG_CRHIT;
				b4 = res.data[1].AVG_WEHIT;
				b5 = res.data[1].AVG_WIDHIT;
				b6 = res.data[1].AVG_CTHIT;
				b7 = res.data[1].AVG_FLAHIT;
				if (res.data[2] === undefined) {
					c1 = 0;
					c2 = 0;
					c3 = 0;
					c4 = 0;
					c5 = 0;
					c6 = 0;
					c7 = 0;
				} else {
					c1 = res.data[2].AVG_THKHIT;
					c2 = res.data[2].AVG_FDTHIT;
					c3 = res.data[2].AVG_CRHIT;
					c4 = res.data[2].AVG_WEHIT;
					c5 = res.data[2].AVG_WIDHIT;
					c6 = res.data[2].AVG_CTHIT;
					c7 = res.data[2].AVG_FLAHIT;
				};
				let Column1 = {
					categories: ['厚度', '宽度', '终温', '卷温', '凸度', '平度', '楔形'],
					series: [{
							name: "甲班",
							data: [a1, a2, a3, a4, a5, a6, a7]
						}, {
							name: "乙班",
							color: "#f5bb1c",
							data: [b1, b2, b3, b4, b5, b6, b7]
						},
						{
							name: "丙班",
							data: [c1, c2, c3, c4, c5, c6, c7]
						},
						{
							name: "丁班",
							data: [0, 0, 0, 0, 0, 0, 0]
						}
					]
				};
				this.$refs.mingzhong.changeData('mingzhong', Column1)
			},

			changetime2(val) {
				this.timeIndex1 = val;
				let _self = this;
				if (this.timeIndex1 == 0) {
					uni.showToast({
						icon: 'loading',
						title: "正在加载",
						success() {
							if (_self.flag) {
								_self.getMingzhong({
									db: "oracle",
									sql: "SELECT CREW,\n" +
										"       ROUND(AVG(THKHIT)) AS AVG_THKHIT,\n" +
										"       ROUND(AVG(FDTHIT)) AS AVG_FDTHIT,\n" +
										"       ROUND(AVG(CRHIT)) AS AVG_CRHIT,\n" +
										"       ROUND(AVG(WEHIT)) AS AVG_WEHIT,\n" +
										"       ROUND(AVG(WIDHIT)) AS AVG_WIDHIT,\n" +
										"       ROUND(AVG(CTHIT)) AS AVG_CTHIT,\n" +
										"       ROUND(AVG(FLAHIT)) AS AVG_FLAHIT\n" +
										"  FROM V_CREW_STAT\n" +
										" WHERE TIME_DISCHARGE >=\n" +
										"       TO_DATE('2018-02-01 0:00:00', 'YYYY-MM-DD HH24:MI:SS')\n" +
										"   AND TIME_DISCHARGE <\n" +
										"       TO_DATE('2018-02-01 10:00:00', 'YYYY-MM-DD HH24:MI:SS')\n" +
										" GROUP BY CREW\n" +
										" ORDER BY DECODE(CREW, '甲班', 0, '乙班', 1, '丙班', 2, 3) ASC"
								})
							} else {
								_self.getMingzhong({
									sql: "SELECT CREW, ROUND(AVG(THKHIT)) AS AVG_THKHIT, ROUND(AVG(FDTHIT)) AS AVG_FDTHIT, ROUND(AVG(CRHIT)) AS AVG_CRHIT, ROUND(AVG(WEHIT)) AS AVG_WEHIT, ROUND(AVG(WIDHIT)) AS AVG_WIDHIT, ROUND(AVG(CTHIT)) AS AVG_CTHIT, ROUND(AVG(FLAHIT)) AS AVG_FLAHIT FROM V_CREW_STAT_TS WHERE TO_CHAR(TIME_DISCHARGE, 'YYYY-MM-DD') = TO_CHAR(SYSDATE, 'YYYY-MM-DD') and pro_id =" +
										_self.id + " GROUP BY CREW ORDER BY DECODE(CREW, '甲班', 0, '乙班', 1, '丙班', 2, 3) ASC "
								})
							}
						}
					})
				}
				if (this.timeIndex1 == 1) {
					uni.showToast({
						icon: 'loading',
						title: '正在加载',
						success() {
							if (_self.flag) {
								_self.getMingzhong({
									db: "oracle",
									sql: "SELECT CREW,\n" +
										"       ROUND(AVG(THKHIT)) AS AVG_THKHIT,\n" +
										"       ROUND(AVG(FDTHIT)) AS AVG_FDTHIT,\n" +
										"       ROUND(AVG(CRHIT)) AS AVG_CRHIT,\n" +
										"       ROUND(AVG(WEHIT)) AS AVG_WEHIT,\n" +
										"       ROUND(AVG(WIDHIT)) AS AVG_WIDHIT,\n" +
										"       ROUND(AVG(CTHIT)) AS AVG_CTHIT,\n" +
										"       ROUND(AVG(FLAHIT)) AS AVG_FLAHIT\n" +
										"  FROM V_CREW_STAT\n" +
										" WHERE TIME_DISCHARGE >=\n" +
										"       TO_DATE('2018-02-01 0:00:00', 'YYYY-MM-DD HH24:MI:SS')\n" +
										"   AND TIME_DISCHARGE <\n" +
										"       TO_DATE('2018-02-08 0:00:00', 'YYYY-MM-DD HH24:MI:SS')\n" +
										" GROUP BY CREW\n" +
										" ORDER BY DECODE(CREW, '甲班', 0, '乙班', 1, '丙班', 2, 3) ASC"
								})
							} else {
								_self.getMingzhong({
									sql: "SELECT CREW,\n" +
										"       ROUND(AVG(THKHIT)) AS AVG_THKHIT,\n" +
										"       ROUND(AVG(FDTHIT)) AS AVG_FDTHIT,\n" +
										"       ROUND(AVG(CRHIT)) AS AVG_CRHIT,\n" +
										"       ROUND(AVG(WEHIT)) AS AVG_WEHIT,\n" +
										"       ROUND(AVG(WIDHIT)) AS AVG_WIDHIT,\n" +
										"       ROUND(AVG(CTHIT)) AS AVG_CTHIT,\n" +
										"       ROUND(AVG(FLAHIT)) AS AVG_FLAHIT\n" +
										"  FROM V_CREW_STAT_TS\n" +
										" WHERE TIME_DISCHARGE >=\n" +
										"       trunc(sysdate -7)\n" +
										"and pro_id =" + _self.id +
										" GROUP BY CREW\n" +
										" ORDER BY DECODE(CREW, '甲班', 0, '乙班', 1, '丙班', 2, 3) ASC"
								})
							}
						}
					})
				}
				if (this.timeIndex1 == 2) {
					uni.showToast({
						icon: 'loading',
						title: "正在加载",
						success() {
							if (_self.flag) {
								_self.getMingzhong({
									db: "oracle",
									sql: "SELECT CREW,\n" +
										"       ROUND(AVG(THKHIT)) AS AVG_THKHIT,\n" +
										"       ROUND(AVG(FDTHIT)) AS AVG_FDTHIT,\n" +
										"       ROUND(AVG(CRHIT)) AS AVG_CRHIT,\n" +
										"       ROUND(AVG(WEHIT)) AS AVG_WEHIT,\n" +
										"       ROUND(AVG(WIDHIT)) AS AVG_WIDHIT,\n" +
										"       ROUND(AVG(CTHIT)) AS AVG_CTHIT,\n" +
										"       ROUND(AVG(FLAHIT)) AS AVG_FLAHIT\n" +
										"  FROM V_CREW_STAT\n" +
										" WHERE TIME_DISCHARGE >=\n" +
										"       TO_DATE('2017-06-01 0:00:00', 'YYYY-MM-DD HH24:MI:SS')\n" +
										"   AND TIME_DISCHARGE <\n" +
										"       TO_DATE('2018-06-01 0:00:00', 'YYYY-MM-DD HH24:MI:SS')\n" +
										" GROUP BY CREW\n" +
										" ORDER BY DECODE(CREW, '甲班', 0, '乙班', 1, '丙班', 2, 3) ASC"
								})
							} else {
								_self.getMingzhong({
									sql: "SELECT CREW,\n" +
										"       ROUND(AVG(THKHIT)) AS AVG_THKHIT,\n" +
										"       ROUND(AVG(FDTHIT)) AS AVG_FDTHIT,\n" +
										"       ROUND(AVG(CRHIT)) AS AVG_CRHIT,\n" +
										"       ROUND(AVG(WEHIT)) AS AVG_WEHIT,\n" +
										"       ROUND(AVG(WIDHIT)) AS AVG_WIDHIT,\n" +
										"       ROUND(AVG(CTHIT)) AS AVG_CTHIT,\n" +
										"       ROUND(AVG(FLAHIT)) AS AVG_FLAHIT\n" +
										"  FROM V_CREW_STAT_TS\n" +
										" WHERE TIME_DISCHARGE >=\n" +
										"       trunc(sysdate -365)\n" +
										"and pro_id =" + _self.id +
										" GROUP BY CREW\n" +
										" ORDER BY DECODE(CREW, '甲班', 0, '乙班', 1, '丙班', 2, 3) ASC"
								})
							}
						}
					})
				}
			},

			//产量时间切换
			//时间配置
			changetime(val) {
				this.timeIndex2 = val
				let _self = this
				if (this.timeIndex2 == 0) {
					uni.showToast({
						icon: 'loading',
						title: "正在加载",
						success() {
							_self.getServerData([{
								sql: "select * from STATISTIC WHERE to_char(DATE_,'YYYY-MM-DD') = '2018-11-28' order by NO"
							}, {
								sql: "select SUM(BLOCKS) as TOTAL from STATISTIC WHERE  to_char(DATE_,'YYYY-MM-DD') = '2018-11-28' "
							}], [{
								sql: "select * from STATISTIC WHERE to_char(DATE_,'YYYY-MM-DD') = '2018-11-28' order by NO"
							}, {
								sql: "select SUM(LENGTH) as TOTAL from STATISTIC WHERE  to_char(DATE_,'YYYY-MM-DD') = '2018-11-28' "
							}], [{
								sql: "select * from STATISTIC WHERE to_char(DATE_,'YYYY-MM-DD') = '2018-11-28' order by NO"
							}, {
								sql: "select SUM(WEIGHT) as TOTAL from STATISTIC WHERE to_char(START_TIME,'YYYY-MM-DD') = '2018-11-23' "
							}],'day');
						}
					})
				};
				if (this.timeIndex2 == 1) {
					uni.showToast({
						icon: 'loading',
						title: '正在加载',
						success() {
							_self.getServerData([{
								sql: "select SUM(BLOCKS) as BLOCKS from STATISTIC where DATE_ >= TO_DATE('2018-11-22','YYYY-MM-DD') and DATE_ < TO_DATE('2018-11-29','YYYY-MM-DD') GROUP BY DATE_ order by DATE_"
							}, {
								sql: "select SUM(BLOCKS) as TOTAL from STATISTIC where DATE_ >= TO_DATE('2018-11-22','YYYY-MM-DD') and DATE_ < TO_DATE('2018-11-29','YYYY-MM-DD')"
							}], [{
								sql: "select SUM(LENGTH) as LENGTH from STATISTIC where DATE_ >= TO_DATE('2018-11-22','YYYY-MM-DD') and DATE_ < TO_DATE('2018-11-29','YYYY-MM-DD') GROUP BY DATE_ order by DATE_"
							}, {
								sql: "select SUM(LENGTH) as TOTAL from STATISTIC where DATE_ >= TO_DATE('2018-11-22','YYYY-MM-DD') and DATE_ < TO_DATE('2018-11-29','YYYY-MM-DD')"
							}], [{
								sql: "select SUM(WEIGHT) as WEIGHT from STATISTIC where DATE_ >= TO_DATE('2018-11-22','YYYY-MM-DD') and DATE_ < TO_DATE('2018-11-29','YYYY-MM-DD') GROUP BY DATE_ order by DATE_"
							}, {
								sql: "select SUM(WEIGHT) as TOTAL from STATISTIC where DATE_ >= TO_DATE('2018-11-22','YYYY-MM-DD') and DATE_ < TO_DATE('2018-11-29','YYYY-MM-DD')"
							}],'week');
						}
					})
				}
				if (this.timeIndex2 == 2) {
					uni.showToast({
						icon: 'loading',
						title: "正在加载",
						success() {
							_self.getServerData(0, 0, 0,'year');
						}
					})
				}
			},

			//停机统计
			changetime1(val) {
				this.timeIndex = val;
				let _self = this;
				if (_self.timeIndex == 0) {
					uni.showToast({
						icon: 'loading',
						title: '正在加载',
						success() {
							setTimeout(function() {
								_self.tingjiCount({"sql":"select sum(pro_id) as sum,shift  from tb_downtimes where TO_CHAR(time_start,'yyyy-MM-dd') > TO_CHAR(sysdate ,'yyyy-MM-dd') group by shift"})
							}, 2000)
						}
					})
				}
				if (_self.timeIndex == 1) {
					uni.showToast({
						icon: 'loading',
						title: '正在加载',
						success() {
							setTimeout(function() {
								_self.tingjiCount({"sql":"select sum(pro_id) as sum,shift  from tb_downtimes where TO_CHAR(time_start,'yyyy-MM-dd') > TO_CHAR(sysdate - 7 ,'yyyy-MM-dd') group by shift"})
							}, 2000)
						}
					})
				}
				if (_self.timeIndex == 2) {
					uni.showToast({
						icon: 'loading',
						title: '正在加载',
						success() {
							setTimeout(function() {
								_self.tingjiCount({"sql":"select sum(pro_id) as sum,shift  from tb_downtimes where TO_CHAR(time_start,'yyyy-MM-dd') > TO_CHAR(sysdate - 365 ,'yyyy-MM-dd') group by shift"})
							}, 2000)
						}
					})
				}
			},
			async tingjiCount(val) {
				let Pie = {
					series: [{ name: '甲组', data: 0 }, { name: '乙组', data: 0 },{ name: '丙组', data: 0 },{ name: '丁组', data: 0 }]
				};
				this.tingji.opts = Pie;
				let data = val?val:{"sql":"select sum(pro_id) as sum,shift  from tb_downtimes where TO_CHAR(time_start,'yyyy-MM-dd') > TO_CHAR(sysdate,'yyyy-MM-dd') group by shift"}
				let res = await post('database/executeQuery', data);
				if(res.data.length !== 0) {
					let PieA = {
						series: [{ name: '甲组', data: res.data[3].SUM }, { name: '乙组', data: res.data[0].SUM },{ name: '丙组', data: res.data[1].SUM },{ name: '丁组', data: res.data[2].SUM }]
					};
					this.$refs.tingji.changeData('tingji', PieA)
				}
			},
			//关闭与修改密码
			close() {
				let _self = this;
				uni.showModal({
					title: '退出登录',
					content: '确定要退出吗？',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							_self.logout();
							// #ifdef APP-PLUS  
							plus.runtime.quit();
							// #endif 
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			changepass() {
				uni.navigateTo({
					url: '/pages/changepass/changepass'
				})
			},
		},

		onNavigationBarButtonTap(e) {
			if (e.float == "right") {
				this.clickShow = !this.clickShow;
			}
		},
		watch: {
			hasLogin() {
				if (!this.$store.state.hasLogin) {
					uni.reLaunch({
						url: '../login/login',
					});
				}
			}
		},
	}
</script>

<style>
	.hezi {
		height: calc(100vh - 110rpx);
	}

	/* 下面主体的高度 */
	.main {
		height: calc(1334rpx - 380rpx);
		padding: 26rpx;
		box-sizing: border-box;
		overflow: hidden;
	}

	/* 二级列表样式 */
	.prodtab {
		width: 248rpx;
		height: 94rpx;
	}

	.timetab {
		margin-top: 44rpx;
		height: 70rpx;
		width: 100%;
		padding: 0 30rpx;
		background: #d9d9d9;
		box-sizing: border-box;
	}

	.timelist {
		float: right;
		display: flex;
		margin: 15rpx 0;
	}

	.jianju {
		height: 60rpx;
	}

	.day {
		height: 40rpx;
		width: 80rpx;
		text-align: center;
		line-height: 40rpx;
		font-size: 24rpx;
		color: #505153;
	}

	.month {
		background: #2353cc;
		color: #FFFFFF;
		border-radius: 5rpx;
	}

	.infomain {
		height: calc(100% - 180rpx);
	}

	.name {
		font-size: 24rpx;
		margin: 10rpx 25rpx;
	}

	.control {
		margin-top: 44rpx;
		height: 140rpx;
		width: 100%;
		background: #d9d9d9;
	}

	.controllist {
		width: 100%;
		height: 70rpx;
		display: flex;
		padding: 0 30rpx;
		box-sizing: border-box;
		color: #505153;
	}

	.controllist-item {
		width: 20%;
		line-height: 70rpx;
		height: 70rpx;
		font-size: 24rpx;
		text-align: center;
	}

	.controllist-val {
		color: #134199;
		background: #E6E6E6;
		padding: 0 30rpx;
		box-sizing: border-box;
	}

	.charts {
		width: 730upx;
		height: 500upx;
		background-color: #F2F2F2;
	}
	
	.mT20{
		margin-top: 20rpx;
	}
</style>
